package com.dolphin.apidriver.service;

import com.dolphin.apidriver.remote.ServiceOrderClient;
import com.dolphin.apidriver.remote.ServiceSsePushClient;
import com.dolphin.common.constant.IdentityConstant;
import com.dolphin.common.dto.ResponseResult;
import com.dolphin.common.request.OrderRequest;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class PayService {

    @Autowired
    ServiceSsePushClient serviceSsePushClient;
    @Autowired
    ServiceOrderClient serviceOrderClient;

    /**
     * 司机发起收款
     * @param orderId
     * @param price
     * @return
     */
    public ResponseResult  pushPayInfo(Long orderId, String price,Long passengerId) {

        //封装消息
        JSONObject message = new JSONObject();
        message.put("orderId", orderId);
        message.put("price", price);
        //修改订单状态
        OrderRequest orderRequest = new OrderRequest();
        orderRequest.setOrderId(orderId);
        serviceOrderClient.pushPayInfo(orderRequest);

        //推送消息
        serviceSsePushClient.push(passengerId, IdentityConstant.PASSENGER_IDENTITY, message.toString());

        return ResponseResult.success();
    }
}
